<template>
  <div class="other_settings">
<!--    <el-card>-->
<!--      <div slot="header">-->
<!--        关注公众号红包-->
<!--      </div>-->
<!--      <el-form :model="follow_red_envelopes" label-width="180px" width="100%">-->
<!--        <el-form-item label="红包类型：">-->
<!--            关注公众号-->
<!--        </el-form-item>-->
<!--        <el-form-item label="是否开启：">-->
<!--          <template>-->
<!--            <el-switch-->
<!--              v-model="follow_red_envelopes.is_open"-->
<!--            />-->
<!--          </template>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="红包金额：">-->
<!--          <el-input v-model="binding_red_envelopes.min_price" class="ipt" placeholder="请输入" /> - -->
<!--          <el-input v-model="binding_red_envelopes.max_price" class="ipt" placeholder="请输入" />  元-->
<!--        </el-form-item>-->
<!--        <el-form-item label="">-->
<!--          <el-button type="primary" @click="handleConserve('follow_red_envelopes')">保存</el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </el-card>-->
    <el-card style="margin-top: 15px;">
      <div slot="header">
        绑定微信公众号红包
      </div>
      <el-form label-width="180px" width="100%">
        <el-form-item label="红包类型：">
          绑定微信
        </el-form-item>
        <el-form-item label="是否开启">
          <el-switch v-model="binding_red_envelopes_is_open" />
        </el-form-item>
        <el-form-item label="红包金额：">
          <el-input v-model="binding_red_envelopes.min_price" class="ipt" placeholder="请输入" /> -
          <el-input v-model="binding_red_envelopes.max_price" class="ipt" placeholder="请输入" />  元
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="handleConserve('binding_red_envelopes')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card style="margin-top: 15px;">
      <div slot="header">
        完善简历送红包
      </div>
      <el-form  label-width="180px" width="100%">
        <el-form-item label="红包类型：">
          完善简历
        </el-form-item>
        <el-form-item label="是否开启">
          <el-switch v-model="improve_resume_red_envelopes_is_open" />
        </el-form-item>
        <el-form-item label="简历完整度要求：">
          <el-input v-model="improve_resume_red_envelopes.Integrity" class="ipt" placeholder="请输入" /> %
        </el-form-item>
        <el-form-item label="红包金额：">
          <el-input v-model="improve_resume_red_envelopes.min_price" class="ipt" placeholder="请输入" /> -
          <el-input v-model="improve_resume_red_envelopes.max_price" class="ipt" placeholder="请输入" />  元
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="handleConserve('improve_resume_red_envelopes')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {redEnvelopesSave } from '@/api/red_envelopes'
import {setConfig} from "@/api/configuration";

export default {
  data () {
    return {
      follow_red_envelopes: '',
      binding_red_envelopes: '',
      binding_red_envelopes_is_open:false,
      improve_resume_red_envelopes_is_open:false,
      improve_resume_red_envelopes: '',
      orderList: []
    }
  },
  created () {
    this.fetchInfo()
  },
  methods: {
    fetchInfo() {
      this.infoLoading = true
      const param = {}
      setConfig(param, 'get')
        .then(response => {
          this.follow_red_envelopes = response.data.follow_red_envelopes
          if(response.data.binding_red_envelopes.is_open == 1){
            this.binding_red_envelopes_is_open = true;
          }else{
            this.binding_red_envelopes_is_open = false;
          }
          this.binding_red_envelopes = response.data.binding_red_envelopes
          if(response.data.improve_resume_red_envelopes.is_open == 1){
            this.improve_resume_red_envelopes_is_open = true;
          }else{
            this.improve_resume_red_envelopes_is_open = false;
          }
          this.improve_resume_red_envelopes = response.data.improve_resume_red_envelopes
        })
        .catch(() => {})
    },
    // 保存
    handleConserve (type) {
      let value = ''
      if (type == 'binding_red_envelopes'){
        value = this.binding_red_envelopes
        value.is_open = this.binding_red_envelopes_is_open
      }
      if (type == 'improve_resume_red_envelopes'){
        value = this.improve_resume_red_envelopes
        value.is_open = this.improve_resume_red_envelopes_is_open
      }
      if(value.min_price > value.max_price || value.min_price == value.max_price){
        this.$message({ message: '最小红包金额不能大于或者等于最大红包金额', type: 'error' })
        return false
      }
      if (value.is_open){
        value.is_open= 1
      }else{
        value.is_open= 0
      }
      let params = {
        'value': value,
        'type': type
      }
      redEnvelopesSave(params).then(res => {
        if (res.code == 200) {
          this.$message({ message: '保存成功', type: 'success' })
        } else {
          this.$message({ message: '保存失败', type: 'error' })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-form-item{
  width: 100%;
  max-width: 920px;
}
.other_settings{
  padding: 20px;
  .ipt{
    width: 220px;
  }
  .tips{
    color: #999;
    margin-left: 10px;
    // white-space:nowrap;
    .icon{
      margin-right: 4px;
    }
  }
}

</style>

